/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package client;
import java.sql.SQLException;
import java.util.ArrayList;
import entreprise.Service;
import entreprise.ServiceService;
/**
 *
 * @author duonghau
 */
public class ServiceBean {
    private String serviceID;
    private String serviceName;
    private float servicePrice;
    private String serviceDescription;
    private String message="";
    private String messageStyle="";
    private String serviceSearchName="";
    private int page=1;
    private int numberOfRowPerPage=10;    

    public String getServiceID() {
        return serviceID;
    }

    public void setServiceID(String serviceID) {
        this.serviceID = serviceID;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public float getServicePrice() {
        return servicePrice;
    }

    public void setServicePrice(float servicePrice) {
        this.servicePrice = servicePrice;
    }

    public String getServiceDescription() {
        return serviceDescription;
    }

    public void setServiceDescription(String serviceDescription) {
        this.serviceDescription = serviceDescription;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMessageStyle() {
        return messageStyle;
    }

    public void setMessageStyle(String messageStyle) {
        this.messageStyle = messageStyle;
    }

    public String getServiceSearchName() {
        return serviceSearchName;
    }

    public void setServiceSearchName(String serviceSearchName) {
        this.serviceSearchName = serviceSearchName;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }
    
    public void getServiceDetail(){
        if(serviceID!=null){
            ServiceService serviceService=new ServiceService();
            Service service=serviceService.getService(serviceID);
            if(service!=null){
                serviceName=service.getServiceName();
                serviceDescription=service.getServiceDescription();
                servicePrice=Float.parseFloat(service.getServicePrice());
            }
        }
    }
    
    public String addService(){
        ServiceService serviceService=new ServiceService();
        if(serviceService.createService(serviceID, serviceName, String.valueOf(servicePrice), serviceDescription)){
            message="Service add success";
            messageStyle="success";                
        }else{
            message="Service add error";
            messageStyle="error";            
        }
        return "services";
    }
    
    public String editService(){
        ServiceService serviceService=new ServiceService();
        if(serviceService.updateService(serviceID, serviceName, String.valueOf(servicePrice), serviceDescription)){
            message="Service update success";
            messageStyle="success";              
        }else{
            message="Service update error";
            messageStyle="error";  
        }
        return "services";
    }
    public String deleteService(String serviceID){
        ServiceService serviceService=new ServiceService();
        if(serviceService.deleteService(serviceID)){
            message="Service delete success";
            messageStyle="success";             
        }else{
            message="Service delete error";
            messageStyle="error";    
        }
        return "services";
    }
    public ArrayList<Service> getServices(){
        ServiceService serviceService=new ServiceService();
        ArrayList<Service> services=serviceService.services(serviceSearchName,(page-1)*numberOfRowPerPage,numberOfRowPerPage);
        return services;
    }
    public ArrayList<Integer> getPagings(){
        ServiceService serviceService=new ServiceService();        
        int numberOfRow=serviceService.getNumberOfServices(serviceSearchName);
        int numberOfPage=(numberOfRow/numberOfRowPerPage);
        if(numberOfRow%numberOfRowPerPage!=0){
            numberOfPage+=1;
        }
        ArrayList<Integer> paging=new ArrayList<>();
        for(int i=1;i<=numberOfPage;i++){
            paging.add(i);
        }
        return paging;
    }    
}
